<?
	/* Se asegura que el archivo es incluido por el index */
	defined( 'LOAD_MODULE_ACTION' ) or die( 'No esta permitido el acceso directo a ' . __FILE__ );
		$this->oTmpObject = new Personal_cuenta_frm( $this );

	class Personal_cuenta_frm extends Frm
	{
	function setValue ( $ncCuenta, $ncPersona )
		{
			$cSql = "SELECT  ncModoLectura,  cUsuario,  cMailbox,  cClave,  cdCuenta
				FROM atPersonalCuenta
				WHERE ncCuenta = '$ncCuenta' AND  ncPersona = '$ncPersona' ";
			$aDatos = $this->oDatabase->getArray($cSql);
			$cMailbox = trim($aDatos['cMailbox']) ;
			if ( substr($cMailbox , 0, 1) == '{' && substr($cMailbox , -1, 1) == '}' )
			{
				$cMailbox = substr($cMailbox , 1, -1);
				$nPos = strpos($cMailbox, '/' );
				if ( $nPos === FALSE )
				{
					$cServidor = $cMailbox;
					$cServicios = '';
				}
				else
				{
					$cServidor = substr( $cMailbox , 0, $nPos );
					$cServicios  = substr( $cMailbox , $nPos +1);
				}
				list ( $aDatos['cServidor'], $aDatos['nPuerto']) = explode ( ':',  $cServidor  );
				$aServicios = explode ( '/', $cServicios );
				foreach( $aServicios  as $cServicio )
				{
					if ( $cServicio == 'imap' || $cServicio == 'pop3' )
					{
						$aDatos['cProtocolo'] =$cServicio;
					}
					if ( $cServicio == 'ssl' ||  $cServicio == 'tls' ||  $cServicio == 'notls'  )
					{
						$aDatos['cSeguridad'] = $cServicio;
					}
					if ( $cServicio  == 'validate-cert' ||  $cServicio == 'novalidate-cert' )
					{
						$aDatos['cCertificado'] = $cServicio;
					}
				}
			}
			$this->setFieldsArray ( $aDatos );
		}
	function Personal_cuenta_frm( &$oModule )
		{
			$this->Frm( $oModule );
			//Crea los Objetos de los campos de edicion
			$this->aFields['ncCuenta']				= new Input( "Codigo, ""ncCuenta", '', false, true );
			$this->aFields['ncPersona']				= new InputLookUp( "Persona", "ncPersona" );
			$this->aFields['cdCuenta']				= new InputText( "Nombre", "cdCuenta" );
			$this->aFields['ncModoLectura']		= new InputList( "Modo", "ncModoLectura" );
			$this->aFields['cServidor']				= new InputText( "Servidor", "cServidor" );
			$this->aFields['cProtocolo']				= new InputList( "Protocolo",  "cProtocolo" );
			$this->aFields['nPuerto']					= new InputNumber( "Puerto", "nPuerto" );
			$this->aFields['cSeguridad']			= new InputList( "Seguridad", "cSeguridad" );
			$this->aFields['cCertificado']			= new InputList( "Certificado", "cCertificado" );
			$this->aFields['cUsuario']				= new InputText( "cUsuario", "cUsuario" );
			$this->aFields['cClave']					= new InputText( "Clave", "cClave" );
		}
	function initializeForm()
		{
			// Si viene el Ubicacion hace el retrieve
				if ( $this->isRetrievable() && $this->aFields['ncCuenta']->getValue() && $this->aFields['ncPersona']->getValue() )
				{
					$this->setValue( $this->aFields['ncCuenta']->getValue(), $this->aFields['ncPersona']->getValue() );
				}
			// Configura el Titulo
				$this->setLabel( "Cuenta de correo" );
			return true;
		}
	function initializeField( $cField , &$oField )
		{
			switch ( $cField )
			{
					case 'ncPersona':
						$oField->setDefault( $this->oModule->oUserSession->getUser() );
						$oField->setHidden();
						/*
						$oField->setLabel('ncPersona');
						initializePersonal( $oField );
						$oField->setMandatory($this->isMandatory());
						*/
					break;
					case 'ncModoLectura':
						$cSql = "SELECT ncModoLectura, cdModoLectura FROM acModoLectura WHERE ncModoLectura = 3";
						$oField->setMatrix($this->oDatabase->getMatrix($cSql));
						$oField->setMandatory($this->isMandatory());
					break;
					case 'cProtocolo':
						$oField->addOption('pop3', 'Pop3');
						$oField->addOption('imap', 'Imap');
					break;
					case 'cSeguridad':
						$oField->addOption('', 'Nada');
						$oField->addOption('notls', 'Nunca');
						$oField->addOption('ssl', 'ssl');
						$oField->addOption('tls', 'tls');
					break;
					case 'cCertificado':
						$oField->addOption('validate-cert', 'Valide certificado de tls/ssl');
						$oField->addOption('novalidate-cert', 'No valide certificado ');
					break;
					case 'cClave':
						$oField->setPassword();
					break;
			}
 		}
	}
?>